Lesson 11 - String manipulation

Left, right and mid are some of the main string functions. Python does not have these functions as it uses a special form of character access. st[2:4] would return the third and forth letter of the string st. You can get a substring by specyfying the start and end characters in this way. so st[x:y] would access the x'th character to the y-1 character.


s = "hello bert"
print s[1] # print e
print s[6:10] # print bert
print s[0:3] # print hel
print s[0:1] # print h
print s[0:2] # print he

Python does, however, have a len function as well lower() and upper(). These are demonstrated in the code below.

 


s = "hello bert"
s = s.upper() 
print s # print HELLO BERT
s = s.lower()
print s # print hellow bert
print len(s) # print 10
# you can combine methods and substring!
print s[6:10].upper() # print BERT